package cn.piaoyi.service.imp;

import java.util.*;
import org.apache.commons.logging.*;
import cn.piaoyi.bean.Payment;
import cn.piaoyi.dao.PaymentDAO;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.PaymentService;


public class PaymentServiceImp implements PaymentService {

	private static final Log logger = LogFactory.getLog(PaymentServiceImp.class);
	
	private PaymentDAO paymentDAO;

	public PaymentDAO getPaymentDAO() {
		return paymentDAO;
	}

	public void setPaymentDAO(PaymentDAO paymentDAO) {
		this.paymentDAO = paymentDAO;
	}

	/**
	 * 保存Payment对象
	 * 
	 * @param payment
	 * 			Payment对象
	 * @return Payment
	 * 			Payment对象
	 */
	public Payment createPayment(Payment payment) throws PiaoyiException{
		try {
			payment = this.getPaymentDAO().savePayment(payment);
			return payment;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据code获取Payment对象
	 * 
	 * @param code
	 * 			String
	 * @return Payment
	 * 			Payment对象
	 */
	public Payment findPaymentByCode(String code){
		return this.getPaymentDAO().findPaymentByCode(code);
	}
	
	/**
	 * 保存Payment对象
	 * 
	 * @param payment
	 * 			Payment对象
	 * @return Payment
	 * 			Payment对象
	 */
	public Payment updatePayment(Payment payment) throws PiaoyiException{
		try {
			payment = this.getPaymentDAO().updatePayment(payment);
			return payment;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Payment对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Payment
	 * 			Payment对象
	 */
	public Payment findPaymentById(long id){
		return this.getPaymentDAO().findPaymentById(id);
	}
	
	/**
	 * 获取Payment列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @return List
	 * 			Admin对象列表
	 */
	public List findPayments(String orderby, int ascOrDesc){
		return this.getPaymentDAO().findPayments(orderby, ascOrDesc);
	}
	
	/**
	 * 删除Payment对象
	 */
	public void removePaymentById(long id){
		this.getPaymentDAO().removePaymentById(id);
	}
}
